<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <h1>修改商品页面</h1>
    <input type="text" v-model="p.id">
    <input type="text" v-model="p.title">
    <input type="text" v-model="p.price">
    <input type="text" v-model="p.num">
    <input type="submit" value="更新商品" @click="upt()">

</div>
<!--引入axios和vue框架文件-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
    let v = new Vue({
        el:"body>div",
        data:{
            p:{
                id:"",title:"",price:"",num:""
            }
        },
        methods:{
            upt(){
                //发出异步修改请求
                axios.post("/update",v.p).then(function (response) {
                    alert("修改成功");
                    location.href="/list.html";
                })
            }
        },
        created:function (){
            //发送请求通过商品id查询商品信息
            axios.get("selectById"+location.search).then(function (response) {
                //服务器端响应的是Java对象
                //客户端得到的是js对象
                v.p = response.data;
            })
        }
    })
</script>
</body>
</html>